//
//  SKUDefultScrPublicV.m
//  ZITHER
//
//  Created by weixin on 2018/8/16.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "SKUDefultScrPublicV.h"
#import "SKUDetailReceiveVC.h"
@implementation SKUDefultScrPublicV

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setCornerRadiusWithRadius:10 isMasks:YES];
        [self setBorderWithColor:[UIColor RGBColorWithR:224 g:224 b:224] width:1.5];
        [self setUI];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [[tap rac_gestureSignal] subscribeNext:^(id x) {
            NSLog(@"跳转公开货源");

            SKUDetailReceiveVC *vc = [[SKUDetailReceiveVC alloc]init];
            vc.goodsid = self.model.goodsId;
            vc.IsEnquiry = ![self.model.myEnquiryFlag isEqualToString:@"1"];
            
            vc.str = @"公开的货源";
            [self.getNav pushViewController:vc animated:YES];
        }];
        
        [self addGestureRecognizer:tap];
        
        _arrM = [[NSMutableArray alloc]init];

    }
    return self;
}

-(void)setUI{
    
    [self addSubview:self.labtitle];
    
    QMUIButton * btn = [[QMUIButton alloc]initWithFrame:CGRectMake(self.frame.size.width-60, 15,50, 50)];
    btn.centerY = self.labtitle.centerY;
    [btn setImage:[UIImage imageNamed:@"sku_btn_into"] forState:UIControlStateNormal];
    btn.userInteractionEnabled = YES;
    [self addSubview:btn];

    [self addSubview:self.labSubtitle];
    
    
    
    NSString *str = @"前些天再网上看了很多网友再谈论一个很有意思的问题，有关算法的。然后小编追根溯源终于扎到了这篇帖子。说是有位网友在面试小米Java岗三次后，终于挺进了第三轮面试，结果还是败在了两道算法题上面。";
    self.labSubtitle.text = str;
    CGRect frame = self.labSubtitle.frame;
    frame.size.height =  [NSString textHeight:str font:15 width:kScreenW-80];
    self.labSubtitle.frame = frame;
    
 

}

-(void)setArrM:(NSArray *)arrM{
    _arrM = arrM;
    
}



-(QMUILabel *)labtitle{
    if (!_labtitle) {
        _labtitle = [[QMUILabel alloc]initWithFrame:CGRectMake(15,15 , 200, 20)];
        _labtitle.font = [UIFont systemFontOfSize:20];
        _labtitle.text = @"31个更多的公开资源";
    }
    return _labtitle;
}

-(QMUILabel *)labSubtitle{
    if (!_labSubtitle) {
        _labSubtitle = [[QMUILabel alloc]initWithFrame:CGRectMake(20,70, kScreenW-65, 15)];
        _labSubtitle.font = [UIFont systemFontOfSize:15];
        _labSubtitle.numberOfLines = 0;
    }
    return _labSubtitle;
}

-(void)setModel:(skuDetailModel *)model{
    _model = model;
    
  
    
    NSString *str1 = [NSString stringWithFormat:@"%@个更多公开货源",model.openSourceCount];
    self.labtitle.text = str1;
    self.labSubtitle.text = model.sourceDesc;
    CGRect frame = self.labSubtitle.frame;
    
    frame.size.height = [NSString textHeight:model.sourceDesc font:15 width:self.labSubtitle.frame.size.width];
    self.labSubtitle.frame = frame;
    CGFloat height = 0;
    
    if (model.fileList.count>0) {
        height = 80;
        
        UIScrollView *scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.labSubtitle.frame)+5 , kScreenW,60)];
        scrollview.bounces = NO;
        scrollview.backgroundColor = [UIColor randomColor];
        scrollview.showsHorizontalScrollIndicator = NO;
        scrollview.contentSize = CGSizeMake(kScreenW*3,0);
        scrollview.bounces = NO; // 默认为YES 取消设置NO
        // 当bounces属性为NO时，以下两个属性设置无效
        scrollview.alwaysBounceHorizontal = YES; // 水平方向弹簧效果
        scrollview.alwaysBounceVertical = YES; // 垂直方向弹簧效果
        scrollview.decelerationRate = 0.1; // 值域 0~1 值越小减速停止的时间越短
        scrollview.backgroundColor = [UIColor whiteColor];
        [self addSubview:scrollview];
        
        
        scrollview.contentSize = CGSizeMake(68*model.fileList.count+15,0);
        
        for (int j = 0; j<model.fileList.count; j++) {
            UIImageView * imageV = [[UIImageView alloc]initWithFrame:CGRectMake(j*68+15,0, 60,60)];
            [imageV setCornerRadiusWithRadius:5 isMasks:YES];
            imageV.backgroundColor = [UIColor whiteColor];
            imageV.contentMode = UIViewContentModeScaleAspectFill;
            
            NSString *str = [NSString stringWithFormat:@"%@%@",RootUrlImage,model.fileList[j]];
            
            [imageV sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:@"watchSmale"]];
            
            
            [scrollview addSubview:imageV];
        }
        
    }
    
    CGRect rect = self.frame;
    rect.size.height = [NSString textHeight:self.labSubtitle.text font:15 width:self.labSubtitle.frame.size.width]+120+height;
    self.frame = rect;
    //    [self mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.height.mas_equalTo([NSString textHeight:self.labSubtitle.text font:15 width:self.labSubtitle.frame.size.width]+120+height);
//    }];
//
//    [self layoutIfNeeded];
    
    
    
    
    
}

@end
